/*
    <ShareToSNS class, share information using inner links>
    Copyright (C) <2011>  <Liao Chen>

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
    
 */
package com.iShare.io;

import android.content.Context;
import android.content.Intent;
import android.widget.Toast;

import com.iShare.R;

public class ShareToSNS {
	private static final int MAX_LENGTH = 120;

	public static boolean share(String shareMessage, Context mContext){
		if(shareMessage!=null){
			if(shareMessage.length()>MAX_LENGTH){
				// If the string is too long, just have it trimmed
				shareMessage=shareMessage.substring(0, MAX_LENGTH-4)+"...";
				Toast.makeText(mContext, mContext.getString(R.string.text_too_long), Toast.LENGTH_LONG).show();
			}
    		Intent intent=new Intent(Intent.ACTION_SEND);    
            intent.setType("text/plain");
        	intent.putExtra(Intent.EXTRA_SUBJECT, mContext.getString(R.string.text_share_link));
	        intent.putExtra(Intent.EXTRA_TEXT,shareMessage+" "+mContext.getString(R.string.text_share_link));     
	        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);    
	        mContext.startActivity(Intent.createChooser(intent, mContext.getString(R.string.text_share_with_others)));    
        }
        else
        {
        	Toast.makeText(mContext, mContext.getString(R.string.text_fail_to_share), Toast.LENGTH_LONG).show();
        }
		return false;		
	}
}
